package com.gnerv.battle.boot.project.guard.business.impl;

import com.gnerv.battle.boot.common.base.model.RestResult;
import com.gnerv.battle.boot.common.tools.UUIDTools;
import com.gnerv.battle.boot.project.guard.business.MonitorProjectNodeBusiness;
import com.gnerv.battle.boot.project.guard.model.bo.MonitorProjectNodeBO;
import com.gnerv.battle.boot.project.guard.model.dto.MonitorProjectNodeCreateDTO;
import com.gnerv.battle.boot.project.guard.model.dto.MonitorProjectNodeDTO;
import com.gnerv.battle.boot.project.guard.model.dto.MonitorProjectNodeUpdateDTO;
import com.gnerv.battle.boot.project.guard.service.MonitorProjectNodeService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author Gnerv LiGen
 */
@Slf4j
@Service
@AllArgsConstructor
public class MonitorProjectNodeBusinessImpl implements MonitorProjectNodeBusiness {

    private final MonitorProjectNodeService monitorProjectNodeService;

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public RestResult<Void> create(MonitorProjectNodeCreateDTO monitorProjectNodeCreateDTO) {
        MonitorProjectNodeBO monitorProjectNodeBO = monitorProjectNodeCreateDTO.toMonitorProjectNodeBO();
        monitorProjectNodeBO.setUkId(UUIDTools.lower());
        monitorProjectNodeService.create(monitorProjectNodeBO);
        return RestResult.ok();
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public RestResult<Void> deleteByUkId(String ukId) {
        monitorProjectNodeService.deleteByUkId(ukId);
        return RestResult.ok();
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public RestResult<Void> updateByUkId(MonitorProjectNodeUpdateDTO monitorProjectNodeUpdateDTO) {
        monitorProjectNodeService.updateByUkId(monitorProjectNodeUpdateDTO.toMonitorProjectNodeBO());
        return RestResult.ok();
    }

    @Override
    @Transactional(readOnly = true)
    public RestResult<MonitorProjectNodeDTO> selectByUkId(String ukId) {
        return RestResult.ok(monitorProjectNodeService.selectByUkId(ukId));
    }

    @Override
    @Transactional(readOnly = true)
    public RestResult<List<MonitorProjectNodeDTO>> listByName(String name, Integer page, Integer size) {
        return RestResult.ok(monitorProjectNodeService.listByName(name, page, size));
    }

}
